	var splitStr = ",";//禁止删除此变量		用来分割多元素时数据分割符！
	

var initElement = function(data,isDisable,container){
	var _container = container==null?document.forms[0]:container;
	for(each in data){
		var _type = null;
		$('#'+each).each(function(){
			_type  = this.type;
			if(isDisable){
				if(_type =='select-one'  ||_type =='select' || _type =='radio'){
					$("<input type='hidden' id='"+each+"' name='"+each+"'>").val(data[each]).appendTo(_container);
				}else if(_type =='select-multiple' ){
					if(typeof data[each] == 'object'){
						var createHTML='';
						for(ov in data[each]){
							createHTML += "<INPUT TYPE='checkbox' id='"+each+"' name='"+each+"' value='"+data[each][ov]+"' checked style='display:none'>";
						}
						$(createHTML).appendTo(_container);
					}else{
						$("<input type='input' id='"+each+"' name='"+each+"' >").val(data[each]).appendTo(_container);
					}
					
				}
			}
		});
		if(_type != null){
			if(_type =='checkbox' || _type =='radio' ){
				var isObj = (typeof data[each] == 'object');
				$( "input[id='"+each+"']").each(function(){
						var compareValue = this.value;
						if(isObj){
							var isChecked = false;
							$.each(data[each],function(i,v){
								if(compareValue == v){
									isChecked = true;
								}
							});
							this.checked = isChecked;
						}else{
							if(data[each].indexOf(splitStr)>-1){
								var tmp = data[each]+splitStr;
								if(tmp.indexOf(this.value+splitStr)>-1){
									this.checked = true;
								}else{
									this.checked = false;
								}
							}else{
								if(data[each]== this.value){
									this.checked = true;
								}else{
									this.checked = false;
								}
							}
						}
				});
			}else{
				$('#'+each).val(data[each]);
			}	
		}	
	}
	if(isDisable){
		$('select,input:radio').each(function(){
			this.disabled = true;
		});
		$('input').attr('readonly','readonly');
		$('input:checkbox').each(function(){
			this.onclick = function(){
				return false;
			}
		});
	}
}
	
	/**
	*	初始化页面表单元素值 
	* @param _data json对象，即是元素值
	* @param isReadOnly 是否设为只读 true OR false
	*/
	function	initElementData(_data,isReadOnly){
		if(_data == null){
			return;
		}
		var _obj;
		for(each in _data){
			 _obj = document.getElementById(each);
			 if(_obj != null){	
				 if(isReadOnly){
					_obj.readOnly = true;
				 }else{
					_obj.readOnly = false;
				 }
				var _value = _data[each];
				var type = _obj.type;
				
				if(type=='radio' || type=='checkbox'){
					_obj = document.getElementsByName(each);
					for(var i=0;_obj!=null&&i<_obj.length;i++){
						if(_value!=null){
							if(typeof _value == 'object'){									
									for(var j=0;j<_value.length;j++){
										if(_value[j] == _obj[i].value){
											_obj[i].checked = true;
											break;
										}else{
											_obj[i].checked = false;
										}
									}
								
							} else{
								var compareValue = _value.toString()+splitStr;
								
								if(compareValue.indexOf(_obj[i].value+splitStr)>-1){
									_obj[i].checked = true;
								}else{
									_obj[i].checked = false;
								}
							}
						}else{
							_obj[i].checked = false;
						}
						if(isReadOnly){
							_obj[i].disabled = true;
						}else{
							_obj[i].disabled = false;
						}
					}
				}else if(type=='select' || type=='select-multiple'){
					for(var i=0;i<_obj.options.length;i++){
						if(_value!=null){
							if(typeof _value == 'object'){
								for(var j=0;_value!=null&&j<_value.length;j++){
									if(_value[j] == _obj.options[i].value){
										_obj.options[i].selected = true;
										break;
									}else{
										_obj.options[i].selected = false;
									}
								}
							}else{
								var compareValue = _value.toString()+splitStr;
								if( compareValue.indexOf(_obj.options[i].value+splitStr)>-1){
									_obj.options[i].selected = true;
								}else{
									_obj.options[i].selected = false;
								}
							}
						}else{
							_obj.options[i].selected = false;
						}
					
					}
					if(isReadOnly){
						_obj.disabled = true;
					}else{
						_obj.disabled =false;
					}
				}else{
					_obj.value = _value==null?'':_value.toString();
					
				}

			 }else{
				var newElement = document.createElement("INPUT");
				newElement.id = each;
				newElement.type = 'hidden';
				newElement.value = _data[each];
				document.body.appendChild(newElement);
				
			 }
		}
	}
	
	/**
	* 将页面表单的所有内容值获取后转为Json对象字符串
	*/
	function getElementValueToJson(_filterElementId){
		var needType = ["text","radio","checkbox","select","hidden"];
		isNeedType = function(elementType){		
			if(elementType==null || elementType == 'undefinded'){
				return -1;
			}
			for(var i=0;i<needType.length;i++){
				if(elementType.indexOf(needType[i])>-1){
					return i;
				}
			}
			return -1;
		}
		getKey = function(obj){
			if(obj.id!=null){
				return obj.id;
			}else if(obj.name!=null){
				return obj.name;
			}
			return null;
		}
		getSelectValue = function(obj){
			var  values = [];
			for(var i=0;obj!=null&&i<obj.options.length;i++){
				if(obj.options[i].selected){
					values.push((obj.options[i].value));
				}
			}
			if(values.length==0){
				return null;
			}
			return values.join(splitStr);
		}
		getBoxValue = function(tagName){
			var _obj = document.getElementsByName(tagName);
			var values = [];
			for(var i=0;_obj!=null&&i<_obj.length;i++){
				if(_obj[i].checked){
					values.push((_obj[i].value));
				}
			}
			if(values.length==0){
				return null;
			}
			return values.join(splitStr);
		}
		hasValue = function(key){
			for(var i=0;i<ss.length;i++){
				if(ss[i] == key){
					return true;
				}
			}
			return false;
		}
		isfilter = function(element){
			if(_filterElementId == null){
				return true;
			}
			if(element==null ||element.id == null){
				return false;
			}
			var filterType;
			if(typeof _filterElementId =='object'){
				for(each in _filterElementId){
					filterType = _filterElementId[each];
					if(filterType == 'indexOf'){
						if(element.id.indexOf(each)>-1){
							return false;
						}
					}else if(filterType == 'equal'){
						if(element.id == each){
							return false;
						}
					}
				}	
			}else{
					if(element.id.indexOf(_filterElementId)>-1){
							return false;
					}
			}
			return true;
		}
		var allElements = getAllElements();
		var ss=[];
		var index=-1;
		var key;
		for(var i=0;i<allElements.length;i++){
			if(isfilter(allElements[i])){
				index = isNeedType(allElements[i].type);
				if(index>-1){
					key = getKey(allElements[i]);
			
					if(key != null && key != '' && !hasValue(key)){
						if(index == 0 || index == 4){
							ss.push(key+':"'+String((allElements[i].value)).formatSplitStr()+'"');
						}else if(index == 1 || index == 2){
							ss.push(key+':"'+String(getBoxValue(key)).formatSplitStr()+'"');
						}else if(index == 3){
							ss.push(key+':"'+String(getSelectValue(allElements[i])).formatSplitStr()+'"');
						}
					}
				}
			}
		}
		return ("{"+ss.join(',')+"}");
	}


function getAllElements(){
	var agt = navigator.userAgent.toLowerCase();
	var is_ie = (agt.indexOf("msie") != -1);
	var is_ie5 = (agt.indexOf("msie 5") != -1);
	var is_opera = (agt.indexOf("opera") != -1);
	var is_mac = (agt.indexOf("mac") != -1);
	var is_gecko = (agt.indexOf("gecko") != -1);
	var is_safari = (agt.indexOf("safari") != -1);

	var All = (is_ie || is_ie5) ? document.all : document.getElementsByTagName("*");
	return All;
}

/**
* 将对象中某个元素含有对象字符串的转化成一个对象 只支持一层对象展现
* 例： {a:"a",b:"b",c:"{d:'d',e:'e'}"} 转化完为： {a:"a",b:"b",d:'d',e:'e'} 
*/
function toObject(obj){
	var myObj = {};
	var value;
	for(each in obj){
		value = obj[each];
			if(typeof value!='object'){	
				if(value.toString().indexOf('{')>-1 && value.toString().indexOf('}')>-1){
					try{
						var cObj = value.toObj();
						for(elem in cObj){
							myObj[elem] = cObj[elem];
						}
					}catch(e){
						myObj[each] = value;
					}
				}else{
					myObj[each] = value;
				}
			}
	}
	return myObj;
}

String.prototype.formatSplitStr = function(){
	return this.replaceAll(':','{@#}').replaceAll(',','{#@}');
}
String.prototype.backBefore = function(){
	return this.replaceAll('{@#}',':').replaceAll('{#@}',',');
}
/**
* 将对象字符串转化为DataBaseRequest 的参数对象
*/
String.prototype.toParamData = function(formatIndex){
	if(formatIndex==null||formatIndex.length<1){
		return null;
	}
	var checkParam = function(str){
		var t =str.split(':');
		for(var i=0;formatIndex!=null&&i<formatIndex.length-1;i++){
			if(formatIndex[i] == t[0]){
				return t;
			}
		}
		return null;
	}
	var sss = this.substring(1,this.length-1);
	var p = sss.split(',');
	var paramData = {};
	var info = [];
	var checkData;
	for(var i=0;i<p.length;i++){
		checkData = checkParam(p[i]);
		if(checkData!=null){
			paramData[checkData[0]] = checkData[1].substring(1,checkData[1].length-1);
		}else{
			if((p[i].trim()).length>0){
				info.push(p[i]);
			}
		}
	}
	paramData[formatIndex[formatIndex.length-1]] = "{"+info.join(',')+"}";
	return paramData;
}